/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef SHARED_BINARY_WORLDPACKET_H_
#define SHARED_BINARY_WORLDPACKET_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <cstddef>
#include <cstdint>
#include "Shared/Binary/ByteBuffer.h"
#include "Shared/OpcodeDefine.h"


namespace Shared {
namespace Binary {

    class WorldPacket: public ByteBuffer
    {
    public:
        WorldPacket(void) 
            : ByteBuffer(0), _opcode(MSG_NULL_ACTION)
        {

        }

        explicit WorldPacket(std::uint16_t opcode, std::size_t res = 200)
            : ByteBuffer(res)
            , _opcode(opcode)
        {

        }

        WorldPacket(const WorldPacket& packet)
            : ByteBuffer(packet)
            , _opcode(packet._opcode)
        {

        }

        virtual ~WorldPacket(void) {}

        void initialize(std::uint16_t opcode, std::size_t newres = 200)
        {
            clear();
            _storage.reserve(newres);
            _opcode = opcode;
        }

        inline std::uint16_t opcode(void) const {
            return _opcode;
        }
        inline void setOpcode(std::uint16_t opcode) {
            _opcode = opcode;
        }

    private:
        std::uint16_t _opcode;
    };

}}

#endif // SHARED_BINARY_WORLDPACKET_H_
